/*
 * twi_func.c
 *
 * Created: 15.09.2013 22:27:31
 *  Author: maxim
 */ 

#include "TWI_Master.h"
#include <stdio.h>

void twi_setup() {
    TWI_Master_Initialise();
}

#define PCA_ADDR 0b1110000

void twi_test() {
    unsigned char twi_buf[4];
    
    printf("Test TWI\r\n");
    twi_buf[0]=PCA_ADDR<<1;
    twi_buf[1]=0b11011;
    TWI_Start_Transceiver_With_Data(twi_buf,2);

    twi_buf[0]=(PCA_ADDR<<1)|1;
    TWI_Start_Transceiver_With_Data(twi_buf,1);
    
    while(TWI_Transceiver_Busy()) {
    }
    
    if(TWI_statusReg.lastTransOK) {
        TWI_Get_Data_From_Transceiver(twi_buf,2);
        printf("\r\nresult from PCA:%x",twi_buf[1]);
        } else {
        printf("\r\n Error from PCA:%x",TWI_Get_State_Info());
    }
    
}


